/**********************************************
*  Namespace: Phx
*  Classes:   CdnPhysicsManager
*  Desc:      Handles all physics in the game.
*             Singleton class.
*  Author:    Vaios Kalpias-Ilias (C) 2008-2009
***********************************************/

#ifndef CDNPHYSICSMANAGER_H
#define CDNPHYSICSMANAGER_H

#include <list>
#include "Vector.h"
#include "Quaternion.h"

namespace Phx
{
	// struct that holds physics info
	struct CdnRigidBody
	{
		// position
		mth::Vector3 pos;
		// velocity
		mth::Vector3 vel;
		// acceleration
		mth::Vector3 acc;
		// orientation
		mth::Quaternion orient;
		// angular velocity
		mth::Quaternion angVel;
		// angular acceleration
		mth::Quaternion angAcc;
	};

	class CdnPhysicsManager
	{
	public:

		typedef std::list<CdnRigidBody> RigidBodyList;

		// returns single instance
		static CdnPhysicsManager* GetInstance();
		// destroys single instance
		static void Destroy();

		// adds rigid body to the euler integration list
		void RegisterRigidBodyEuler (const CdnRigidBody& rigidBody);
		// adds rigid body to the RK4 integration list
		void RegisterRigidBodyRk4 (const CdnRigidBody& rigidBody);
		// performs physics step
		void Update(float dt);

	private:

		// single instance
		static CdnPhysicsManager* m_pInstance;
		// rigid body list for euler integration
		RigidBodyList m_lEulerRigidBodies;
		// rigid body list for RK4 integration
		RigidBodyList m_lRk4RigidBodies;

		// ctor - dtor
		CdnPhysicsManager();
		~CdnPhysicsManager();

		// performs euler integration
		void IntegrateEulerList(float dt);
		// performs RK4 integration
		void IntegrateRk4List(float dt);

	}; // end of class CdnPhysicsManager

} // end of namespace Phx


#endif